﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Web;

namespace AlumniProject.Framework
{
    public class BaiVietAccess
    {
        readonly DBAccess _dba = new DBAccess();
        public DataTable LoadLinhVuc()
        {
            const string procName = "LINHVUC_LOAD_PROC";
            return _dba.ExcuteQuery(procName, CommandType.StoredProcedure, null);
        }

        public bool LuuBaiViet(TinDangEntity tinDang)
        {
            var res = false;

            const string procName = "TINDANG_LUU_PROC";

            SqlParameter[] parameters =
            {
                new SqlParameter("@TIEUDE",SqlDbType.NVarChar), 
                new SqlParameter("@NOIDUNG",SqlDbType.NVarChar), 
                new SqlParameter("@TENDN",SqlDbType.VarChar), 
                new SqlParameter("@NGAYDANG",SqlDbType.SmallDateTime), 
                new SqlParameter("@LINHVUC",SqlDbType.VarChar), 
            };

            parameters[0].Value = tinDang.TieuDe;
            parameters[1].Value = tinDang.NoiDung;
            parameters[2].Value = tinDang.TenDangNhap;
            parameters[3].Value = tinDang.NgayDang;
            parameters[4].Value = tinDang.LinhVuc;
            res = _dba.ExcuteNonQuery(procName, CommandType.StoredProcedure, parameters);
            return res;
            }
            public TinDangEntity loadtindang(string id)
            {
                TinDangEntity tindang = new TinDangEntity();
                SqlParameter[] para = { new SqlParameter("@id", SqlDbType.Int) };

                para[0].Value = id;
                DataTable table = _dba.ExcuteQuery("tindang_loadone_proc", CommandType.StoredProcedure, para);
                tindang.TieuDe = table.Rows[0][1].ToString();
                tindang.NoiDung = table.Rows[0][3].ToString();
                return tindang;
            }
            public DataTable LoadTinTucSK()
            {
                const string procName = "TinDang_Load_TinTucSK";
                return _dba.ExcuteQuery(procName, CommandType.StoredProcedure, null);
            }

            public DataTable LoadTinMoiNhat()
            {
                const string procName = "TinDang_Load_NgayGanNhat";
                return _dba.ExcuteQuery(procName, CommandType.StoredProcedure, null);
            }

            public DataTable LoadTinTuyenDung()
            {
                const string procName = "TinDang_Load_TinTuyenDung";
                return _dba.ExcuteQuery(procName, CommandType.StoredProcedure, null);
            }
            public DataTable LoadTinDongGop()
            {
                const string procName = "TinDang_Load_TinDongGop";
                return _dba.ExcuteQuery(procName, CommandType.StoredProcedure, null);
            }

    }
}